package DB;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import bean.Rijibean;
import bean.Userbean;

public class Rijidb {
 public static List<Rijibean> getrijilist(){
	 List<Rijibean> alllist=new ArrayList<>();
	 String sql = null;
		DBHelper db1 = null;
		sql = "select *from riji";// SQL
		db1 = new DBHelper(sql);//
		ResultSet ret = null;
		
		try {
			ret = db1.pst.executeQuery();
			while (ret.next()) {
				int id=ret.getInt(1);
				String title = ret.getString(2);
				String content = ret.getString(3);
				String time=ret.getString(4);
				Rijibean rijis = new Rijibean();
				rijis.setId(id);
				rijis.setTitle(title);
				rijis.setContent(content);
				rijis.setTime(time);
				alllist.add(rijis);
			} //
			ret.close();
			db1.close();//
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //
		return alllist;
 }
 //插入数据
 public static int insert(String title,String content,String time) {
	    String sql = null;
		DBHelper db1 = null;
		sql ="INSERT INTO `riji` (`title`, `content`, `time`) VALUES ('"+title+"', '"+content+"', '"+time+"')";// SQL
		db1 = new DBHelper(sql);//
		int ret=0;
		try {
			ret=db1.pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ret;
		
 }
 
 public static int update() {
	 
	 String sql=null;
	 DBHelper db1=null;
	 int ret=0;
	 
	 
	 return ret;
 }
 
 
}
